<template>
  <div class="box">
    <header class="header">user header</header>
    <div class="content">
      <button @click="logout">退出</button>
    </div>
  </div>
</template>
<script>
import { mapMutations } from 'vuex'
export default {
  methods: {
    ...mapMutations({ // 在当前的组件中生成changeIsLogin函数，实际上就是this.$store.commit('changeIsLogin', false)
      changeIsLogin: 'user/changeIsLogin' // 按照模块操作
    }),
    logout () {
      localStorage.removeItem('userid')
      localStorage.removeItem('token')
      localStorage.removeItem('isLogin')
      // this.$store.commit('changeIsLogin', false)
      this.changeIsLogin(false)
      this.$router.replace('/login')
    }
  }
}
</script>
